package game;

import java.awt.Point;
import java.util.List;
import java.util.ArrayList;

/**
 * Creates a new Knight for either chess or the Knight's problem.
 * 
 * @author Nicole Waldrum
 * @date January 30, 2010
 * @version 1.0
 *
 * @author Mark Kelly
 * @date February 19, 2010
 * @version 2.0
 * 
 * @author Trevor Bastian
 * @date February 20, 2010
 * @version 2.0
 */
public class Knight extends Piece {	
	/**
	 * Creates a new instance of Knight
	 * 
	 * @param name the name of this Knight
	 * @param position the initial position of this Knight
	 * @param team the team that this Knight is on
	 */
	public Knight(String name, Point position, Team team) {
		super(name, position, team);
	}
	
	/**
	 * Creates a new instance of Knight
	 * 
	 * @param position the initial position of the Knight
	 * @param team the team that the Knight is on
	 */
	public Knight(Point position, Team team) {
		this((team == Team.WHITE) ? "WN" : "BN", position, team);
	}

	/**
	 * Assumes that 'isValidMove()' has been called and returns true first
	 * {@inheritDoc}
	 */
	@Override
	public List<Point> checkMovePattern(Point dest) {
		List<Point> ret = new ArrayList<Point>();
		ret.add(dest);
		return ret;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isValidMove(Piece piece, Point dest) {
		Point start = piece.getLocation();
		
		if (((int) Math . abs ( start.getX () - dest . getX ()) == 2 ) && ((int) Math . abs ( start . getY () - dest . getY ()) == 1))
			return super.isValidMove(piece, dest);
		if (((int) Math . abs ( start . getX () - dest . getX ()) == 1 ) && ((int) Math . abs ( start . getY () - dest . getY ()) == 2 ))
			return super.isValidMove(piece, dest);

		return false;
	}
}
